<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box,#list{
            margin: 0;
            padding: 0;

        }
        .box{
            display: inline-block;
        }
        .box #list{
            display: none;
        }
        .box #list li{
            list-style: none;
            border: 1px solid #000;
        }
    </style>
</head>
<body>
    <div class="box">
        <input id="txt">
        <ul id="list">
            <li>第1个</li>
            <li>第2个</li>
            <li>第3个</li>
            <li>第4个</li>
            <li>第5个</li>
        </ul>
    </div>

    <script>
        var  oList=document.querySelector("#list");
        var oText=document.querySelector("#txt");
        var oBox=document.querySelector(".box");
        oText.onfocus=function(){
            oList.style.display="block";
        }
        document.onclick=function(evt){
            var e=evt||window.event;
            var ele=e.target||e.srcElement;
            if(["HTML","BODY"].indexOf(ele.nodeName)!=-1){
                oList.style.display="none";
            }
        }

        oList.onmouseover=function(evt){
            var e=evt||window.event;
            var ele=e.evt||e.srcElement;
            if(ele.nodeName!="LI"){
                return;
            }

            var oLis=ele.parentNode.children;
            for(var i=0;i<oLis.length;i++){
                oLis[i].style.backgroundColor="";
            }
            ele.style.backgroundColor="skyblue";
        }
        

        //事件委托
        oList.onclick=function(evt){
            var e=evt||window.event;
            var ele=e.target||e.srcElement;
            if(ele.nodeName!="LI"){
                return;
            }
            oText.value=ele.innerText;
            oList.style.display="none";
        }
    </script>
</body>
</html>